//
//  XMSSimpleDownloadManager+DefualtStorePath.m
//  etionCBLogic
//
//  Created by wjxfhxy on 14-5-5.
//  Copyright (c) 2014年 GuangZhouXuanWu. All rights reserved.
//

#import "XMSSimpleDownloadManager+Extend.h"

@implementation XMSSimpleDownloadManager (DefualtStorePath)

+ (NSString*)currentSimpleDownloadManagerStorePath
{
    return [[XLGContext context].m_szUserdefaulteppath stringByAppendingPathComponent:@"SimpleDownload"];
}

- (void)addDownloadTask:(NSString *)szUrl inDefaultPathWithAttachment:(id)attachment
{
    NSString *currentPath = [XMSSimpleDownloadManager currentSimpleDownloadManagerStorePath];
    if([XMSFileHelper isDirExist:currentPath]!=YES)
        [XMSFileHelper createDir:currentPath];
    currentPath = [currentPath stringByAppendingPathComponent:[szUrl lastPathComponent]];
    [self addDownloadTask:szUrl path:currentPath attachment:attachment];
}

@end

@implementation XMSSimpleDownloadManager (FileHTTPAddress)

- (void)downloadFile:(NSString *)fileName withStorePath:(NSString *)storePath attachment:(id)attachment
{
    NSString *URL = [XLGContext fileDownloadURL:fileName];
    [self addDownloadTask:URL path:storePath attachment:attachment];
}

- (void)downloadThumbImageFile:(NSString *)fileName withStorePath:(NSString *)storePath attachment:(id)attachment
{
    NSString *URL = [XLGContext thumbImageDownloadURL:fileName];
    [self addDownloadTask:URL path:storePath attachment:attachment];
}

- (void)downloadThumbImageFile:(NSString *)fileName thumbSize:(CGSize)thumbSize withStorePath:(NSString *)storePath attachment:(id)attachment
{
    NSString *URL = [XLGContext thumbImageDownloadURL:fileName];
    URL = [NSString stringWithFormat:@"%@?thumbSize=%fx%f", URL, thumbSize.width, thumbSize.height];
    [self addDownloadTask:URL path:storePath attachment:attachment];
}

- (BOOL)isContainDownloadFile:(NSString *)fileName
{
    NSString *URL = [XLGContext fileDownloadURL:fileName];
    return [self isContainDownloadURL:URL];
}

- (BOOL)isContainDownloadThumbImageFile:(NSString *)fileName
{
    NSString *URL = [XLGContext thumbImageDownloadURL:fileName];
    return [self isContainDownloadURL:URL];
}

@end

